<template>
  <div style="height: 50px;line-height: 50px;border-bottom: 1px solid #ccc;display: flex">
    <div style="width: 200px;padding-left: 30px;font-weight: bold;color: #42b983">超省星后台管理系统</div>
    <div style="flex: 1"></div>
    <div style="width: 100px;margin: 20px 0">
      <el-dropdown>
      <span class="el-dropdown-link">
      管理员
      <el-icon class="el-icon--right">
        <arrow-down/>
      </el-icon>
      </span>
        <template #dropdown>
          <el-dropdown-menu>
            <el-dropdown-item @click="update">修改密码</el-dropdown-item>
            <el-dropdown-item @click="$router.push('/')">退出</el-dropdown-item>
          </el-dropdown-menu>
        </template>
      </el-dropdown>
    </div>
  </div>

  <div style="margin: 10px 0">
    <el-dialog v-model="dialogVisible" title="修改密码" width="30%">
      <el-form :model="form" label-width="120px">

        <el-form-item label="原密码" >
          <el-input prop="oldpassword" v-model="form.oldpassword" style="width: 80%" />
        </el-form-item>

        <el-form-item label="新密码">
          <el-input prop="newpassword" v-model="form.newpassword" style="width: 80%"/>
        </el-form-item>

      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button type="primary" @click="save" >确认</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import request from "@/utils/request";

export default {
  name: "Header",
  data(){
    return{
      form:{},
      dialogVisible:false
    }
  },
  methods:{

    update(){
      this.dialogVisible = true;
      this.form = {};
    },
    save(){
        //更新
        request.put("/api/user", this.form).then(res => {
          console.log(res)
          if (res.code == '200'){
            this.$message({
              type:"success",
              message:"更新成功"
            })
          }else{
            this.$message({
              type:"error",
              message:res.msg
            })
          }
          this.load()//刷新表格数据
          this.dialogVisible = false//关闭弹窗
        })
    },
  }
}
</script>


<style scoped>

</style>
